package com.link.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;

import com.common.util.Constants;
import com.link.po.Account;
import com.link.service.AuthenticationService;
import com.link.service.LinkService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.others.util.Constants2;

public class BaseAction extends ActionSupport implements SessionAware, Preparable, Constants, Constants2 {

    private static final long serialVersionUID = -3895424140223547839L;

    public void prepare() throws Exception {
        setFieldErrors(new HashMap<String, List<String>>());
        setActionErrors(new ArrayList<String>());
        setActionMessages(new ArrayList<String>());
    }
    
    
    protected void iniBaseInfo() {
        setGroupAccountList(getAuthenticationService().getAccountListByType(true));
    }

    private AuthenticationService authenticationService;
    private LinkService linkService;


    public AuthenticationService getAuthenticationService() {
        return authenticationService;
    }
    public void setAuthenticationService(AuthenticationService authenticationService) {
        this.authenticationService = authenticationService;
    }
    public LinkService getLinkService() {
        return linkService;
    }
    public void setLinkService(LinkService linkService) {
        this.linkService = linkService;
    }

    private Account account;
    private boolean loginFailedFlag;
    private boolean addLinkFailedFlag;
    private List<Account> groupAccountList;

    public List<Account> getGroupAccountList() {
        return groupAccountList;
    }


    public void setGroupAccountList(List<Account> groupAccountList) {
        this.groupAccountList = groupAccountList;
    }


    public Account getAccount() {
        return account;
    }
    public void setAccount(Account account) {
        this.account = account;
    }

    public boolean isLoginFailedFlag() {
        return loginFailedFlag;
    }
    public void setLoginFailedFlag(boolean loginFailedFlag) {
        this.loginFailedFlag = loginFailedFlag;
    }
    public boolean isAddLinkFailedFlag() {
        return addLinkFailedFlag;
    }
    public void setAddLinkFailedFlag(boolean addLinkFailedFlag) {
        this.addLinkFailedFlag = addLinkFailedFlag;
    }
    
    public boolean isFailed() {
        return (loginFailedFlag || addLinkFailedFlag);
    }

    private Map<String, Object> session;
    public Map<String, Object> getSession() {
        return session;
    }
    public void setSession(Map<String, Object> session) {
        this.session = session;
    }
    public HttpServletResponse getResponse() {
        return ServletActionContext.getResponse();
    }
    public HttpServletRequest getRequest() {
        return ServletActionContext.getRequest();
    }
}
